package com.yuantong.xyerp.core.provider.dao;

import com.yuantong.xyerp.core.api.model.Attachment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AttatchmentMapper {
    @Results(id = "Attatchment",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "masterId",column = "master_id"),
            @Result(property = "contentType",column = "content_type"),
            @Result(property = "name",column = "name"),
            @Result(property = "fileName",column = "file_name"),
            @Result(property = "filePath",column = "file_path"),
            @Result(property = "fileSize",column = "file_size"),
            @Result(property = "md5Value",column = "md5_value"),
            @Result(property = "sha1Value",column = "sha1_value"),
            @Result(property = "suffix",column = "suffix"),
            @Result(property = "uploadTime",column = "upload_time"),
            @Result(property = "uploaderId",column = "uploader_id")
    })

    @Select("SELECT id,master_id,content_type,name,file_name,file_path,file_size,md5_value,sha1_value,suffix,"+
    "upload_time,uploader_id FROM t_attachment where id=#{id} and status=1")
    Attachment getById(@Param("id") String id);

    @Insert("INSERT INTO t_attachment set id=#{id},master_id=#{masterId},content_type=#{contentType},name=#{name},"+
            "file_name=#{fileName},file_path=#{filePath},file_size=#{fileSize},md5_value=#{md5Value},sha1_value=#{sha1Value},"+
            "suffix=#{suffix},upload_time=#{uploadTime},uploader_id=#{uploaderId},status=1")
    void insert(Attachment attachment);

    @Delete("UPDATE t_attachment SET status=0,delete_time=NOW() where id=#{id}")
    void deleteById(String id);

    @Select("SELECT id,master_id,content_type,name,file_name,file_path,file_size,md5_value,sha1_value,suffix,"+
            "upload_time,uploader_id FROM t_attachment where master_id=#{masterId} and status=1")
    @ResultMap(value = "Attatchment")
    List<Attachment> findByMasterId(String masterId);
}
